#include "config.h"
#include "FreeRTOS.h"
#include "task.h"

TaskHandle_t config_task_handler;

extern QueueHandle_t configMsgHandle;

void configTaskInit(){
  config_eepprom_init();
}

void configTask(void * param){
    char *msg;
    while (1)
    {
			//printf("---------\r\n");
      if(xQueueReceive(configMsgHandle,&msg, portMAX_DELAY)==pdTRUE){
			    //printf("message=%s\r\n",msg);
         //根据消息的类型进行区分去处理
          dispatchMsg(msg);
      }

      //vTaskDelay(1000);
    }
	  
    
}

void createConfigTask(){
  xTaskCreate(configTask,"configTask",128,NULL,2,&config_task_handler);
}

void dispatchMsg(char *msg){
    //1.获取消息类型
    int type= parseMsgType(msg);
    //2.根据消息类型 做处理
    switch (type)
    {
			case MSG_TYPE_CONFIG_TH:
					//调用处理阈值类配置的函数
					configTh(msg);
					break;
			case MSG_TYPE_CONFIG_NETWORK:
					//调用处理网络类配置函数
					configNetwork(msg);
					break;    
    }
}